﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Loong.AspNetCore.Mvc.ExceptionHandling;
using Loong.AspNetCore.Mvc.Results;
using Loong.AspNetCore.Mvc.Uow;

namespace Loong.AspNetCore.Mvc
{
    public static class MvcExtensions
    {
        public static MvcOptions AddCustomFilters(this MvcOptions options)
        {
            var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
            options.Filters.Add(new AuthorizeFilter(policy));

            options.Filters.AddService(typeof(UowActionFilter));
            options.Filters.AddService(typeof(LoongExceptionFilter));
            options.Filters.AddService(typeof(LoongResultFilter));

            return options;
        }
    }
}
